package com.tedu07.lcl.mapper;

import com.tedu07.lcl.entity.Resources;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ResourcesMapper {

    @Select("select * from resources where md5=#{md5Str}")
    Resources checkMD5(String md5Str);

    @Insert("insert into resources values(null,#{name},#{md5},#{path},#{size},#{upUid},#{upTime},#{downTimes},#{quantity},#{gmtCreate},#{gmtModified})")
    void addResources(Resources resources);

    @Select("select rid from resources where path=#{filePath}")
    Resources selectIdByFilePath(String filePath);

    @Update("update resources set quantity=quantity-1 where rid=#{rid}")
    void reduce(int rid);

    @Update("update resources set quantity=quantity+1 where rid=#{rid}")
    void increase(int rid);

    @Select("select * from resources where rid=#{rid}")
    Resources selectById(int rid);

    @Delete("delete from resources where rid=#{rid}")
    void deleteById(int rid);

//    @Select("select * from resources r left join file f on r.id=f.rid where fid=#{fid}")
//    Resources selectResourcesByFid(int fid);
}
